package com.hcss.sys.modulelog.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hcss.common.base.BaseClass;
import com.hcss.sys.modulelog.dao.HcSysModulelogComplexMapper;
import com.hcss.sys.modulelog.dao.HcSysModulelogMapper;
import com.hcss.sys.modulelog.model.HcSysModulelog;
import com.hcss.sys.modulelog.model.HcSysModulelogExample;
import com.hcss.sys.modulelog.model.par.HcSysModulelogPar;
import com.hcss.sys.modulelog.service.HcSysModulelogService;
import com.hcss.util.EmptyUtil;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @描述: HcSysModulelog-服务的实现类
 * @作者: fengzhaodong
 * @创建日期: 2019-09-30 17:08:47
 */
@Service("hcSysModulelogService")
public class HcSysModulelogServiceImpl implements HcSysModulelogService {
	
	@Autowired
	private HcSysModulelogMapper hcSysModulelogMapper;
	@Autowired
	private HcSysModulelogComplexMapper hcSysModulelogComplexMapper;

	@Override
	public PageInfo<HcSysModulelog> queryPagingData(HcSysModulelogPar par) throws Exception{
		PageHelper.startPage(par.getPage(), par.getPerpage());
        List<HcSysModulelog> list =  hcSysModulelogComplexMapper.selectModulelog(par);
        return new PageInfo<>(list);
	}
	
	@Override
	public List<HcSysModulelog> queryAllData(HcSysModulelogPar par) throws Exception {
		return hcSysModulelogComplexMapper.selectModulelog(par);
	}

	@Override
	public void insertModel(HcSysModulelog model) {
		model.setId(BaseClass.getUUIDWithoutConnector());
		model.setLogtime(new Date());
		hcSysModulelogMapper.insertSelective(model);
	}


	@Override
	public HcSysModulelog selectByPK(String id) {
		if (EmptyUtil.isHaveEmpty(id)) return null;

        HcSysModulelogExample example = new HcSysModulelogExample();
        example.createCriteria().andIdEqualTo(id);
		List<HcSysModulelog> list = hcSysModulelogMapper.selectByExample(example);
        return CollectionUtils.isEmpty(list) ? null : list.get(0);
	}
}
